<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="copyright" content="www.apicloud.com" />
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
<title></title>
<link rel="stylesheet" type="text/css" href="../css/api.css" />
<style>
	html {height: 100%;}
	body {height: 100%;background: #f0f0f0;}
	
	input {height: 50px;font-size: 18px;color: #8E8C8C;width: 80%;}
	input::-webkit-input-placeholder {color: #ccc;}
	.divider {height: 15px;}
	.email,.passwd {/*margin-top: 3px;*/background: #fff;}
	.passwd img, .email img {vertical-align: top;}
	.item {background-color: #fff; border-bottom: 1px solid #e0e0e0;position: relative;}
	/*.email, .passwd, .btn {margin:3px 10px;}*/
	.btn {margin:3px 10px;}
	.btn {background: #41ab54;height: 40px; text-align: center; line-height: 40px; font-size: 20px;margin-top: 20px;border-radius: 5px;}
	.btn button {color: #fff;}
	.email img {width: 25px; margin-top: 15px; margin-left: 10px; margin-right: 9px;}
	.passwd img {height: 25px;margin-top: 10px; margin-left: 10px;margin-right: 10px;}
	input {outline: none;}
</style>
</head>
<body>
		<div class="divider"></div>
		<div class="item email"><img src="../image/username.png" alt=""><input type="text" placeholder="用戶名" id="pwuser"></div>
		<div class="item passwd"><img src="../image/passwd.png" alt=""><input type="password" placeholder="密碼" id="pwpwd">
		</div>
		<div class="btn" tapmode="buyhover" onclick="login()"><button type="button">登錄</button></div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/config.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript">
	apiready = function() {

    };
    
    function login(){
    	var pwuser = $api.val($api.byId('pwuser'));
    	var pwpwd = $api.val($api.byId('pwpwd'));
    	
    	if(pwuser.length == 0 || pwpwd.length == 0){
			api.alert({
			    msg: '請填寫用戶名和密碼',
			},function(ret,err){
			});
			
			return false;
    	}
    	
		api.showProgress({
		    style: 'default',
		    animationType: 'fade',
		    title: '登錄中',
		    modal: false
		});
    	
		api.ajax({
		    url: OpenAPI.login,
		    method: 'POST',
		    timeout: 30,
		    dataType: 'text',
		    charset: 'gbk',
		    returnAll:true,
		    data:{
		        values: {
		        	pwuser: pwuser,
		        	pwpwd: pwpwd,
		        	step: 2,
		        	jumpurl: 'index.php',
		        	hideid: 0,
		        	forward: 'index.php',
		        	cktime: 31536000,
		        },
		    },
		},function(ret,err){

			api.hideProgress();
			if (parseInt(ret.statusCode) == 200) {
			
				var rgexp1 = /(您已經順利登錄)|(請不要重複登錄)/;
				var rgexp2 = /密碼錯誤/;
				var rgexp3 = /不存在/;
			    if (rgexp1.test(ret.body)) {	// 登錄成功
					api.execScript({
					    name: 'fixed',
					    script: 'refreshUserInfo();'
					});	
					api.closeWin({name: 'win_login'});
					
			    }else if(rgexp2.test(ret.body)){	// 密碼錯誤
				    var  mErrInfo = ret.body.match(/<center><br \/><br \/><br \/>(.+)<br \/>/);
					var errInfo = mErrInfo[1];
					api.toast({
					    msg: errInfo,
					    duration:2000,
					    location: 'middle'
					});
			    }else if(rgexp3.test(ret.body)){	// 用戶不存在
				    var  mErrInfo = ret.body.match(/用戶<b>(.+)<\/b>不存在/);
					var errInfo = mErrInfo[1];
					api.toast({
					    msg: '用戶 '+errInfo+'不存在',
					    duration:2000,
					    location: 'middle'
					});
			    }else{
					api.toast({
					    msg: '登錄失敗',
					    duration:2000,
					    location: 'middle'
					});
			    }


			}else{
				showErrMgs(err.code, err.msg);
			}

		});
    }
</script>
</html>